<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2021/1/11
  Time: 2:16 下午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/mvc/plugins/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="/mvc/css/common/nav.css">
</head>
<body>
<!--导入导航-->
<%@ include file="../common/nav.jsp"%>

<div class="container-fluid" style="margin-top: -20px">
    <div class="row">
        <img src="/mvc/imgs/banner01.jpg" style="width: 100%">
    </div>
</div>

<div class="container" style="margin-bottom: 10px;margin-top: 10px">
    <div class="row text-center">
        <button type="button" class="btn btn-info" onclick="mgs()">缩略图展示</button>
        <button type="button" class="btn btn-success" onclick="tbls()">表格展示</button>
    </div>
</div>

<div class="container-fluid">
    <div class="row">
        <ul class="breadcrumb">
            <li><a href="#">产品</a></li>
            <li><a href="#">2021</a></li>
            <li class="active">一月</li>
        </ul>
    </div>
</div>

<div class="container-fluid">
    <div class="row">
        <div class="col-md-2">
            <form role="form">
                <div class="form-group">
                    <select id="type_select" onchange="change_type(this)" class="form-control">
                        <option value="-1">===选择类型===</option>
                        <c:forEach items="${typeList}" var="t">
                            <option <c:if test="${typeId==t.id}">selected</c:if> value="${t.id}">${t.name}</option>
                        </c:forEach>
                    </select>
                </div>
            </form>
        </div>
        <div class="col-md-5">
            <div>
                <form class="bs-example bs-example-form" role="form">
                    <div class="row">
                        <div class="col-lg-6">
                            <div class="input-group">
                                <input value="${name}" id="name" placeholder="请你输入产品名" type="text" class="form-control">
                                <span class="input-group-btn">
                        <button onclick="searchs()" class="btn btn-primary" type="button">搜索</button>
                    </span>
                            </div><!-- /input-group -->
                        </div><!-- /.col-lg-6 -->
                    </div><!-- /.row -->
                </form>
            </div>
        </div>
    </div>
</div>

<%--    数据的展示begin--%>
<div class="container-fluid" id="mgs">
    <div class="row">
        <c:forEach items="${productList}" var="p">
            <div class="col-sm-6 col-md-2">
                <div class="thumbnail">
                    <img src="/mvc/imgs/${p.imgUrl}"
                         alt="通用的占位符缩略图">
                    <div class="caption">
                        <h3>${p.name}</h3>
                        <p>价格:${p.price}</p>
                        <p>作者:${p.author}</p>
                        <p>出版社:${p.publishHouse}</p>

                        <c:if test="${user.power==0}">
                            <p class="text-right">
                                <a href="/mvc/product/del?id=${p.id}" class="text-danger">
                                    <span class="glyphicon glyphicon-trash"></span>
                                </a>
                            </p>
                        </c:if>

                    </div>
                </div>
            </div>
        </c:forEach>
    </div>
</div>

<hr>
<div class="container-fluid" id="tbls" style="display: none">
    <div class="row">
        <div class="table-responsive">
            <table class="table">
                <caption>产品</caption>
                <thead>
                <tr>
                    <th>序号</th>
                    <th>产品图</th>
                    <th>产品名称</th>
                    <th>产品价格</th>
                    <th>产品作者</th>
                    <th>生产地址</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${productList}" var="p" varStatus="vs">
                    <tr>
                        <td>${vs.count}</td>
                        <td><img src="/mvc/imgs/${p.imgUrl}" style="width: 70px;height: 70px"></td>
                        <td>${p.name}</td>
                        <td>${p.price}</td>
                        <td>${p.author}</td>
                        <td>${p.publishHouse}</td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </div>
    </div>
</div>


<%--    必须先引入jquery.min.js--%>
<script src="/mvc/plugins/jquery/jquery.min.js"></script>
<script src="/mvc/plugins/bootstrap/js/bootstrap.js"></script>
<script>
    function tbls(){
        let mgs_div = document.getElementById("mgs");
        let tbls_div = document.getElementById("tbls");
        mgs_div.style.display="none";
        tbls_div.style.display="";
    }
    function mgs(){
        let mgs_div = document.getElementById("mgs");
        let tbls_div = document.getElementById("tbls");
        mgs_div.style.display="";
        tbls_div.style.display="none";
    }

    //选择产品的类型
    function change_type(obj){
        //此处的obj变量代表的就是select标签
        //对象.属性
        //alert(obj.value)
        //将产品类型的id的值发送到后台
        window.location='/mvc/product/index?typeId='+obj.value;
    }

    //文本框的搜索
    function searchs(){
        let type_select_value = document.getElementById("type_select").value;
        let name = document.getElementById("name").value;

        window.location='/mvc/product/index?typeId='+type_select_value+"&name="+name;
    }
</script>
</body>
</html>